package com.earnings.okhttputils.utils.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;

import com.earnings.R;
import com.earnings.okhttputils.utils.bean.EarningsData2;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.god.Listener.GodOnClickListener;
import com.earnings.okhttputils.utils.view.mpchart.animation.Easing;
import com.earnings.okhttputils.utils.view.mpchart.charts.PieChart;
import com.earnings.okhttputils.utils.view.mpchart.data.PieData;
import com.earnings.okhttputils.utils.view.mpchart.data.PieDataSet;
import com.earnings.okhttputils.utils.view.mpchart.data.PieEntry;
import com.earnings.okhttputils.utils.view.mpchart.formatter.PercentFormatter;
import com.earnings.okhttputils.utils.view.mpchart.utils.MPPointF;

import java.util.ArrayList;

/**
 * 我的爱心
 * Created by Administrator on 2017/5/9 0009.
 */


public class MyLoveActivity extends GodLeftHandBaseActivity implements GodOnClickListener {

    private PieChart piechart_view;
    private String[] mParties = new String[]{"红心", "蓝心", "绿心", "休眠蓝心"};
    private EarningsData2 data;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_love;
    }

    @Override
    protected void init() {
        setTitle("我的爱心");
        showRightTextView();
        data = (EarningsData2) getIntent().getSerializableExtra("data");              //   "blue":0,			//蓝心

        setText(R.id.blue_number, data.getBlue());
        setText(R.id.bluesleep_number, data.getBluesleep());
        setText(R.id.green_number, data.getGreen());
        float red = Float.parseFloat(data.getRed());
        float blue = Float.parseFloat(data.getBlue());
        float green = Float.parseFloat(data.getGreen());
        float bluesleep = Float.parseFloat(data.getBluesleep());


        back_view.setImageResource(R.mipmap.nav_back02);
        top_view.setBackgroundColor(getResources().getColor(R.color.style));
        title_tv.setTextColor(getResources().getColor(R.color.white));
        top_right_tv.setTextColor(getResources().getColor(R.color.white));

        piechart_view = getView(R.id.piechart_view);
        setOnClickListener(this, R.id.top_right_tv, R.id.up_view);
        setPiechart();
        setData(red,blue,green,bluesleep);
        piechart_view.animateY(1000, Easing.EasingOption.EaseInQuad);

    }

    private void setPiechart() {
        piechart_view.setHighlightPerTapEnabled(false);
        //禁止旋转
        piechart_view.setRotationEnabled(false);
        piechart_view.getDescription().setEnabled(false);
        piechart_view.setExtraOffsets(5, 10, 5, 5);
        piechart_view.setDragDecelerationFrictionCoef(0.95f);
        piechart_view.setHoleColor(Color.WHITE);
        piechart_view.setTransparentCircleColor(Color.WHITE);
        piechart_view.setTransparentCircleAlpha(110);
        piechart_view.setHoleRadius(58f);
        piechart_view.setTransparentCircleRadius(61f);
        //圆从哪个角度开始绘制
        piechart_view.setRotationAngle(270);
    }

    private void setData(float red,float blue,float green,float bluesleep) {
        piechart_view.setLoveData(red,blue,green,bluesleep);

        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
        //红心
        entries.add(new PieEntry(red, mParties[0]));
        //激励蓝心
        entries.add(new PieEntry(blue, mParties[1]));
        //绿心
        entries.add(new PieEntry(green, mParties[2]));
        //休眠蓝心
        entries.add(new PieEntry(bluesleep, mParties[3]));

        PieDataSet dataSet = new PieDataSet(entries);
        dataSet.setDrawIcons(false);
        //圆间距
        dataSet.setSliceSpace(1f);
        dataSet.setIconsOffset(new MPPointF(0, 40));
        dataSet.setSelectionShift(5f);
        // 添加颜色
        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.add(getResources().getColor(R.color.rad));
        colors.add(getResources().getColor(R.color.blue));
        colors.add(getResources().getColor(R.color.green));
        colors.add(getResources().getColor(R.color.grey));
        dataSet.setColors(colors);
        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        //百分比的字体大小
        data.setValueTextSize(0f);
        //百分比的字体颜色
        data.setValueTextColor(Color.WHITE);
        piechart_view.setData(data);
    }


    @Override
    public void OnClickListener(View view) {

        if (view.getId() == R.id.up_view) startActivity(new Intent(this, UpGreenActivity.class));
        if (view.getId() == R.id.top_right_tv) startActivity(new Intent(this, LoveDetailActivity.class));


    }
}
